/*
 * Copyright: Copyright (c)2011
 * Company: 易宝支付(YeePay)
 */

package com.cyl.yeepay.gateway.handler;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.cyl.manager.yee.service.YeeMerchantSifService;
import com.cyl.yeepay.config.YeePayConfig;
import com.cyl.yeepay.vo.OutNotifyRetVo;
import com.yeepay.yop.sdk.service.common.callback.YopCallback;

import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONUtil;

/**
 * 提现回调
 * 
 */
@Component
public class YopOutCallbackHandler extends YopBaseCallbackHandler {

    private static final Logger LOGGER = LoggerFactory.getLogger(YopOutCallbackHandler.class);

    @Autowired
    private YeePayConfig yeePayConfig;
    
    @Autowired
    private YeeMerchantSifService yeeMerchantSifService;
    
    @Override
    public String getType() {
        return "/out/notify";
    }

    @Override
    public void handle(YopCallback callback) {
    	  String json = callback.getBizData();
    	  LOGGER.info("/out/notify :" + json);
    	  OutNotifyRetVo outNotifyRetVo = JSONUtil.toBean(json, OutNotifyRetVo.class);
    	  boolean success = "SUCCESS".equals(outNotifyRetVo.getStatus());
    	  String sbyy  = null; 
    	  if(!success) {
    		  sbyy = json;
    	  } 
    	  String no =  outNotifyRetVo.getRequestNo();
    	  String id = no.substring(16, no.length());
    	  if("C250410015500477923".equals(no)) {//特殊处理
    		  id = "23";
    	  }
    	  yeeMerchantSifService.d2cNotify(Long.parseLong(id), success, outNotifyRetVo.getOrderNo(), sbyy);
    }

 
}